import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os
import sys
from ddt import ddt, file_data
# 怎么把public/common中的方法导入进来
pathmf=os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
# 将其追加到sys.path
sys.path.append(pathmf)
from publick.common import denlu,tuichu,quitbrower

# 创建单元测试类
#@ddt
class mifeng_reg_username(unittest.TestCase):
    def setUp(self):
        # 创建浏览器对象
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get("http://39.101.167.251/qftest/")
        self.driver.find_element(By.LINK_TEXT, "登陆").click()
        self.driver.find_element(By.ID, "username").send_keys("dabai")
        self.driver.find_element(By.ID, "password").send_keys("qwer_123")
        self.driver.find_element(By.LINK_TEXT, '登     陆').click()
        time.sleep(5)

    #@file_data(r"F:\dataa\dataqiantaichongshemimatrue.json")
    def test_mifeng_geren_updata(self):
        self.driver.find_element(By.LINK_TEXT, '安全设置').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div[2]/div/div/dl[4]/dd/p[2]/a').click()
        time.sleep(2)
        self.driver.find_element(By.NAME, "old_password").send_keys("qwer_123")
        self.driver.find_element(By.NAME, "password").send_keys("1213314")
        self.driver.find_element(By.NAME, "repassword").send_keys("1213314")
        self.driver.find_element(By.XPATH, '//*[@id="upform"]/div/button').click()

        # 断言
        expect_value = "密码更改成功，请用新密码重新登录"
        actual_value = self.driver.find_element(By.XPATH, "/html/body/div/div/h3").text
        self.assertEqual(expect_value, actual_value, "预期和实际结果不一致！！")

        def tearDown(self):
            # 退出登录和关闭浏览器
            tuichu(self.driver)


if __name__ == '__main__':
    unittest.main()